package group2assignone.ucm.administrator;

import group2assignone.dao.MyDAO;
import group2assignone.ucm.UCController;
import group2assignone.ucm.UCStartup;
import group2assignone.view.UITool;
import group2assignone.view.administrator.AdminMainView;

/**
 * Use Case: Delete Manager                                                 <br>
 * Pre-condition: User has clicked delete from the Admin Main view.         <br>
 * Post-condition: Administrator main UI Use Case is run                    <br>
 * 1. system checks if a manager is selected                                <br>
 * 2. system closes the  Add Manager view                                   <br>
 * 3. sytem retrieves the user number of manager to delete                  <br>
 * 4. Sytem deletes manager from database                                   <br>
 * 5. system runs the use case UI Admin Main View                           <br>
 *      1. a) No manager was selected                                       <br>
 *              - show error                                                <br>
 * @author group2                                                           <br>
 */
public class UCDeleteManager implements UCController {

    private AdminMainView view;

    public UCDeleteManager(AdminMainView m_view) {
        view = m_view;
    }

    public void run() {
        //1. system checks if a manager is selected
        if (view.getSelectedRow() >= 0) {  //if have selection
            //2. system closes the  Add Manager view
            view.dispose();
            // 3. sytem retrieves the user number of manager to delete
            String userName = view.getUserName();
            //4. Sytem deletes manager from database
            MyDAO coms = UCStartup.getInstance().getDAO();
            boolean worked = coms.sQLDeleteManager(userName);
            //5. system runs the use case UI Admin Main View
            UCUIAdminMainView uc = UCUIAdminMainView.getInstance();
            uc.run();

        } else {
            //  1. a) No manager was selected                                       <br>
            //             - show error
            UITool.displayError("Select a Manager to Delete!!!", view);
        }
    }
}


